// pagesDoctor/doctorIndex/prescriptionReview/index.js
import {
  ApiGetAdviceList
} from '../../../api/docIndex'

Component({
  data: {
    loading: false,
    param: {
      page: 1,
      size: 100,
      finish: false,
    }
  },
  options: {
    addGlobalClass: true
  },
  /**
   * 页面的初始数据
   */

  pageLifetimes: {
    show() {
      this.setData({
        "adviceList": [],
        'param.page': 1,
      })
      this.getAdviceList()
    }
  },
  methods: {
    handlePreClick(e) {
      /*     this.data.list = [] */
      /*     console.log(e) */
      let id = e.currentTarget.dataset.v.id
      wx.navigateTo({
        url: `/pagesDoctor/doctorIndex/prescriptionReviewDetail/index?id=${id}`,
      })
      /*   ApiAdviceInfoByID(id).then(res=>{
  
        }) */

    },


    getAdviceList() {
      wx.showLoading({
        title: '加载中'
      })
      let adviceList = []
      ApiGetAdviceList(this.data.param).then(res => {
        const data = res.data
        adviceList = this.data.param.page === 1 ? data : this.data.adviceList.concat(data)
        if (data.length == 0) {
          this.data.param.finish = true
        }
        res.data.forEach(item => {
          item.medical = JSON.parse(item.medical)
        })
        this.setData({
          adviceList
        })
        console.log(this.data.adviceList)
        wx.hideLoading()
      })
    },


    onLoadMore() {
      if (this.data.loading || this.data.param.finish) return
      this.data.param.page += 1
      this.getAdviceList()
    },


  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    this.getAdviceList()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.param.page = 1
    this.getAdviceList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})